package com.command.self;

public class Controller {

    Command onCommands[];
    Command offCommands[];
    Command undoCommand;

    public Controller() {
        onCommands = new Command[5];
        offCommands = new Command[5];
        for (int i = 0;i<5;i++){
            onCommands[i] = new NoCommand();
            offCommands[i] = new NoCommand();
        }
    }

    public void setCommand(int no, Command onCommand, Command offCommand){
        onCommands[no] = onCommand;
        offCommands[no] = offCommand;
    }

    public void executeOnCommand(int no){
        onCommands[no].execute();
        undoCommand = onCommands[no];
    }

    public void executeOffCommand(int no){
        offCommands[no].execute();
        undoCommand = offCommands[no];
    }

    public void undoCommand(){
        undoCommand.undo();
    }
}
